<extend name="template:common" />
<block name="css">
    <css href="__ZTREE__/css/zTreeStyle/zTreeStyle.css" />
    ul.ztree {
            margin-top: 10px;
            border: 1px solid #617775;
            background: #f0f6e4;
            width: 220px;
            overflow-y: scroll;
            overflow-x: auto;
        }
</block>
<block name="js">
    <script src="__ZTREE__/js/jquery.ztree.core.js"></script>
    <script>
        $(function(){
            $('#namex').focus(function(){
                $val = $('#namex').val();
            }).blur(function(){
                if($('#namex').val()==''){
                    $('#namex').val($val);
                }
            });

            var setting = {
                data: {
                    simpleData: {
                        enable: true,
                        pIdKey:'parent_id',
                    }
                },
                callback:{
                    onClick:function(event,treeId,treeNode,clickFlag){
                        $('#parent_name').val(treeNode.name);
                        $('#parent_id').val(treeNode.id);
                    }
                }
            };

            $(document).ready(function(){
                var zNodes = {$jsondata};
               var ztree_obj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                ztree_obj.expandAll(true);
                //编辑显示父节点
              var parent_node = ztree_obj.getNodeByParam("id", {$row.parent_id|default=0});
                  //判断是否有父节点,默认选中该节点
//                      //把名字和id填到对应的input
                       ztree_obj.selectNode(parent_node);
                       $('#parent_name').val(parent_node.name);
                        $('#parent_id').val(parent_node.id);
//                  }
            });

        });
    </script>
    <block name="main">
        <h1>
            <span class="action-span1"><a href="{:U('index')}">商品管理</a></span>
            <span id="search_id" class="action-span1"> - {$meta_title} </span>
            <div style="clear:both"></div>
        </h1>
        <div class="main-div">
            <form method="post" action="{:U()}"enctype="multipart/form-data" >
                <table cellspacing="1" cellpadding="3" width="100%">
                    <tr>
                        <td class="label">分类名称</td>
                        <td>
                            <input type="text" id="namex" name="name" maxlength="60" value="{$row.name}" />
                            <span class="require-field">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">父级分类</td>
                        <td>
                            <input type="hidden" name="parent_id" id="parent_id">
                            <input type="text" disabled="disabled" id="parent_name"></input>
                            <ul id="treeDemo" class="ztree"></ul>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">商品描述</td>
                        <td>
                            <textarea  name="intro" cols="60" rows="4"  >{$row.intro}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="label">排序</td>
                        <td>
                            <input type="text" name="sort" maxlength="40" size="15" value="{$row.sort}" />
                        </td>
                    </tr>
                    <tr>
                        <td class="label">是否显示</td>
                        <td>
                            <input type="radio" name="status" value="1" checked="checked" /> 是
                            <input type="radio" name="status" value="0"  /> 否
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center"><br />
                            <input type="hidden" value="{$row.id}" name="id">
                            <input type="submit" class="button" value=" 确定 " />
                            <input type="reset" class="button" value=" 重置 " />
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </block>
</block>
